home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#06 (Feb 86)
/
pascal 2.2
/
Four_Tone_test
< prev
next >
Wrap
Text File
|
1985-12-20
|
2KB
|
84 lines
program A_Basic_Scale;
uses
Sane;
type{ for MyStartSound }
Ptr = ^integer;
ParamBlockFake = array[0..30] of integer;
var
rate1 : integer;
MyFTSynth : FTSynthRec;
myFTSound : FTSoundRec;
SinWave : packed array[0..255] of char;
blockA, blockB : ParamBlockFake;{ for myStartSound }
AUsed : boolean;{ for MyStartSound }
procedure MyStartSound (SynthRec : ptr;
numbytes : longint;
CompletionRtn : Ptr);
var
regs : array[0..12] of longint; { for generic }
BlockPtr : ^ParamBlockFake;
begin
if Aused then
BlockPtr := @BlockA
else
BlockPtr := @BlockB;
Aused := not Aused;
BlockPtr^[12] := -4;{ set ioRefNum }
BlockMove(@SynthRec, @BlockPtr^[16], 4);{ ioBuffer }
BlockMove(@numbytes, @BlockPtr^[18], 4);{ ioReqCount }
while BlockPtr^[8] <> 0 do { wait for ioResult }
;
{ The following two lines perform PBWrite(BlockPtr,true) }
regs[0] := ord(BlockPtr);{ set A0 for generic }
Generic($A403, regs);{ Write,async }
end;
{ Fill the array SinWave with bytes (chars) }
{ representing one cycle of a sine wave }
{ note that numbers are from 0 to 255 so that }
{ 128 is 'zero' }
procedure FillSinWave;
var
i : integer;
f, pi : extended;
begin
pi := arcTan(1) * 4;
f := 2 * pi / 256;
for i := 0 to 255 do
SinWave[i] := chr(Num2Integer(sin(i * f) * 120 + 128));
end;
begin
FillSinWave;
ShowText;
MyFTSynth.mode := FTMode;
MyFTSynth.SndRec := @MyFTSound;
{ Note that all MacPascal Records are initialised }
{ by the system to zero. In another pascal you may }
{ have to remember to initialize everything }
{ ie. when we start all rates are 0 }
with MyFTSound do
begin
Duration := 1000;
Sound1Wave := @SinWave[0];
MyStartSound(@MyFTSynth, Sizeof(MyFTSynth), nil);
rate1 := 1024;
repeat
Duration := 1000;
Sound1Rate := FixRatio(rate1, 256);
rate1 := rate1 + rate1 div 16;
writeln('The rate is', rate1, ' div 256, = ', FixRatio(rate1, 256));
if rate1 >= 2048 then
rate1 := 1024;
until Button;
end;
StopSound;
end.